{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thread-6 is running \n",
      "Thread-7 is running \n",
      "Thread-8 is running \n",
      "Thread-9 is running \n",
      "Thread-10 is running \n",
      "Thread-11 is running \n",
      "Thread-12 is running \n",
      "Thread-13 is running \n",
      "Thread-14 is running \n",
      "Thread-15 is running \n",
      "Thread-16 is running \n",
      "Thread-17 is running Thread-18 is running \n",
      "Thread-19 is running \n",
      "\n",
      "Thread-20 is running \n",
      "Thread-21 is running \n",
      "Thread-22 is running \n",
      "Thread-23 is running \n",
      "Thread-24 is running \n",
      "Thread-25 is running \n",
      "Thread-26 is running \n",
      "Thread-27 is running \n",
      "Thread-28 is running \n",
      "Thread-29 is running \n",
      "Thread-30 is running \n",
      "Thread-31 is running \n",
      "Thread-32 is running \n",
      "Thread-33 is running \n",
      "Thread-34 is running \n",
      "Thread-35 is running \n",
      "Thread-36 is running \n",
      "Thread-37 is running \n",
      "Thread-38 is running \n",
      "Thread-39 is running \n",
      "Thread-40 is running \n",
      "Thread-41 is running \n",
      "Thread-42 is running \n",
      "Thread-43 is running \n",
      "Thread-44 is running \n",
      "Thread-45 is running \n",
      "Thread-46 is running \n",
      "Thread-47 is running \n",
      "Thread-48 is running \n",
      "Thread-49 is running \n",
      "Thread-50 is running \n",
      "Thread-51 is running \n",
      "Thread-52 is running \n",
      "Thread-53 is running \n",
      "Thread-54 is running \n",
      "Thread-55 is running \n",
      "Thread-56 is running \n",
      "Thread-57 is running \n",
      "Thread-58 is running \n",
      "Thread-59 is running \n",
      "Thread-60 is running \n",
      "Thread-61 is running \n",
      "Thread-62 is running \n",
      "Thread-63 is running \n",
      "Thread-64 is running \n",
      "Thread-65 is running \n",
      "Thread-66 is running \n",
      "Thread-67 is running \n",
      "Thread-68 is running \n",
      "Thread-69 is running \n",
      "Thread-70 is running \n",
      "Thread-71 is running \n",
      "Thread-72 is running \n",
      "Thread-73 is running \n",
      "Thread-74 is running \n",
      "Thread-75 is running \n",
      "Thread-76 is running \n",
      "Thread-77 is running \n",
      "Thread-78 is running \n",
      "Thread-79 is running \n",
      "Thread-80 is running \n",
      "Thread-81 is running \n",
      "Thread-82 is running \n",
      "Thread-83 is running \n",
      "Thread-84 is running \n",
      "Thread-85 is running \n",
      "Thread-86 is running \n",
      "Thread-87 is running \n",
      "Thread-88 is running \n",
      "Thread-89 is running \n",
      "Thread-90 is running \n",
      "Thread-91 is running \n",
      "Thread-92 is running \n",
      "Thread-93 is running \n",
      "Thread-94 is running \n",
      "Thread-95 is running \n",
      "Thread-96 is running \n",
      "Thread-97 is running \n",
      "Thread-98 is running \n",
      "Thread-99 is running \n",
      "Thread-100 is running \n",
      "Thread-101 is running \n",
      "Thread-102 is running \n",
      "Thread-103 is running \n",
      "Thread-104 is running \n",
      "Thread-105 is running \n",
      "主线程:0.8062989711761475 n:99\n"
     ]
    }
   ],
   "source": [
    "from threading import Thread,current_thread,Lock\n",
    "import os,time\n",
    "def task():\n",
    "    global n\n",
    "    print('%s is running '%current_thread().getName())\n",
    "    temp=n\n",
    "    time.sleep(0.5)\n",
    "    n=temp-1\n",
    "    \n",
    "if __name__=='__main__':\n",
    "    n=100\n",
    "    lock=Lock()\n",
    "    threads=[]\n",
    "    start_time=time.time()\n",
    "    for i in range(100):\n",
    "        t=Thread(target=task)\n",
    "        threads.append(t)\n",
    "        t.start()\n",
    "    for t in threads:\n",
    "        t.join()\n",
    "    stop_time=time.time()\n",
    "    print('主线程:%s n:%s'%(stop_time-start_time,n))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import gevent\n",
    "from concurrent.futures import ThreadPoolExecutor\n",
    "def demo():\n",
    "    l=[i for i in range(100)]\n",
    "    for i in l:\n",
    "        print(i)\n",
    "        gevent.sleep(1)\n",
    "pools=ThreadPoolExecutor(max_workers=50)\n",
    "pools.submit(demo)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "print(4545)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
